/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin		 	*/
/*	Project:	GoLib-1.0.0			*/
/*	Author:		gong_libin			*/
/*	Date:		2016_01_01			*/
/*	File:		GoList.go			*/
/********************************************************/

package GoCap

import (
	. "GoGlb"
)

const (
	GO_LS_MAX	uint = 0x000f4240
)

type GoList	struct {
	cnt	uint
	head	interface{}
	tail	interface{}
}

type GoNode	struct {
	Size	uint
	Data	interface{}
	next	interface{}
}

func (l *GoList) GoListCnt() uint {
	return l.cnt
}

func (l *GoList) GoListPut(v interface{}, s uint) bool {
	r := GO_TRUE
	if l.cnt > 0 {
		if l.cnt < GO_LS_MAX {
			if nil != l.tail {
				n := GoNode{s, v, nil}
				m := l.tail.(*GoNode)
				m.next = &n
				l.tail = &n
				l.cnt += 1
			} else {
				r = GO_FALSE
			}
		} else {
			r = GO_FALSE
		}
	} else {
		n := GoNode{s, v, nil}
		l.head = &n
		l.tail = &n
		l.cnt += 1
	}
	return r
}

func (l *GoList) GoListPop() (interface{}, bool) {
	h := l.head
	b := GO_TRUE
	if nil != h {
		l.cnt -= 1
		l.head = h.(*GoNode).next
		if 0 == l.cnt {
			l.tail = nil
		}
	} else {
		b = GO_FALSE
	}
	return h, b
}
